<!-- 静态代码块 -->
<span>
<select name="province_id" id="province_id">
  <option value="0">请选择</option>
  <#if provinceList??>
    	<#list provinceList as province>
			<option value='${(province.region_id)?c}' >${province.local_name}</option>
		</#list>
	</#if>
</select>&nbsp;
<input type="hidden" name="province" id="province" />

<select name="city_id" id="city_id"><option value="0">请选择</option></select>&nbsp;
<input type="hidden" name="city" id="city" />

<select name="region_id" id="region_id"  ><option value="0">请选择</option></select>&nbsp;
<input type="hidden" name="region" id="region" />	
</span>

<!--js加载代码 -->
<script>
var RegionsSelect={
	init:function(){
		var self  = this;
		$("#province_id").change(function(){
				var province = $(this).val();
				$("#province").val(  $("#province_id option:selected").text() );
				if( "0"  ==  province ){
					$("#city_id").html("<option value='0'>请选择</option>");
					$("#region_id").html("<option value='0'>请选择</option>");
					return }
				$("#region_id").empty().html("<option value='0'>请选择</option>");
				//$("#region_id").hide();
				self.loadRegions(province,$("#city_id"));
		});

		$("#city_id").change(function(){
			$("#city").val(  $("#city_id option:selected").text() );
			var city = $(this).val();
			if( "0"  ==  city ){
				$("#region_id").html("<option value='0'>请选择</option>");
				return }
			//$("#region_id").show();
			self.loadRegions(city,$("#region_id"));

		});
		$("#region_id").change(function(){
			var regionid = $(this).val();//当前选中的区id
			var name = $("#region_id option:selected").text();
			$("#region").val(name);
			self.regionChange(regionid ,name,$("#region_id option:selected").attr("zipcode"));
		});
		
	},
	regionChange:function(name,zipcode){
		
	},load:function(provinceid,cityid,regionid){
		$("#province_id").val( provinceid );
		$("#province").val(  $("#province_id option:selected").text() );
		
		this.loadRegions(provinceid, $("#city_id"), cityid);
		$("#city").val(  $("#city_id option:selected").text() );
		
		this.loadRegions(cityid, $("#region_id"), regionid);
		$("#region").val($("#region_id option:selected").text());
	},
	loadRegions:function(regionid,selectEl,currentid){
		$.ajax({
			url:"${ctx}/api/base/region!getChildren.do?ajax=yes&regionid="+regionid,
			dataType:"json",
			success:function(regionJson){
				if(regionJson){
					var html ="<option value='0'>请选择</option>";
					$.each(regionJson,function(i,region){
						html+="<option value='"+region.region_id+"'";
						
						if( currentid== region.region_id ){
							html += "selected='true'";
						}
						
						if(selectEl.attr("id") == "region_id"){
							html += "zipcode='"+ region.zipcode + "'";
						}
						
						html += ">"+ region.local_name +"</option>";
					});
					selectEl.empty().append(html);
					selectEl.next("input").val(selectEl.find("option:selected").text());
				}
			},
			error:function(){
				alert("非常抱歉,加载地区出错");
			}
		});
	}
	
}

//初始化加载
$(function(){
	RegionsSelect.init();
});
</script>

<!-- 因为是修改 所以要展示你原始的地区 -->
<script>
//初始化地址的选择
  $(function(){
		RegionsSelect.load(${ff.province_id!'0'},${ff.city_id!'0'},0);
		});
</script>